"use strict";
var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
    var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
    if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
    else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
    return c > 3 && r && Object.defineProperty(target, key, r), r;
};
var __param = (this && this.__param) || function (paramIndex, decorator) {
    return function (target, key) { decorator(target, key, paramIndex); }
};
function NotNumber(target, propertyKey, parameterIndex) {
    // console.log(typeof target)
    // console.log(target[`__notNumber_${propertyKey}`])
    // 初始化或获取当前方法的参数索引列表
    console.log(Object.getOwnPropertyDescriptor(target, `__notNumber_${propertyKey}`));
    let notNumberArr = target[`__notNumber_${propertyKey}`] || [];
    // let notNumberArr: number[] = Object.getOwnPropertyDescriptor(target, `__notNumber_${propertyKey}`)?.value || []
    // 将当前参数索引添加到列表中
    notNumberArr.push(parameterIndex);
    // 将列表存储回目标对象
    target[`__notNumber_${propertyKey}`] = notNumberArr;
    // Object.defineProperty(target, `__notNumber_${propertyKey}`, { value: notNumberArr })
    // console.log(target[`__notNumber_${propertyKey}`])
}
// 方法装饰器定义
function Validate(target, propertyKey, descriptor) {
    const method = descriptor.value;
    descriptor.value = function (...args) {
        // 获取被标记为不能为 number 的参数索引列表
        const notNumberArr = target[`__notNumber_${propertyKey}`] || [];
        // 检查番薯是否为 number 
        for (const index of notNumberArr) {
            if (typeof args[index] === 'number') {
                throw new Error(`方法 ${propertyKey} 中索引为 ${index} 的参数不能是数字！`);
            }
        }
        // 调用原始方法
        return method.apply(this, args);
    };
    return descriptor;
}
// 定义类
class Student {
    constructor(name) {
        this.name = name;
    }
    speak(/* @NotNumber */ massage1, /* @NotNumber */ message2) {
        console.log(`${this.name} 想说: ${massage1}, ${message2}`);
    }
    static logInfo(value1, value2) {
        console.log(value1, value2);
    }
}
__decorate([
    Validate
], Student.prototype, "speak", null);
__decorate([
    Validate,
    __param(0, NotNumber),
    __param(1, NotNumber)
], Student, "logInfo", null);
// 使用
const s1 = new Student('tom');
console.log(s1);
console.log(Student);
s1.speak(100, 200);
Student.logInfo(100, 200);
